import java.util.concurrent.locks.ReentrantLock;

public class Test {
    public static int sum = 0;
    public static int count = 10000;
    public static int total = 1000;
    public static void main(String[] args) {
        Object locker = new Object();
        Thread t = new Thread(() -> {
            for(int i = 0; i < 5000; i++) {
                synchronized (locker) {
                    sum++;
                }
                synchronized (locker) {
                    count--;
                }
                synchronized (locker) {
                    total--;
                }
            }
        });
        Thread t2 = new Thread(() -> {
            for(int i = 0; i < 5000; i++) {
                synchronized (locker) {
                    sum++;
                    count--;
                    total--;
                }
            }
        });

        ReentrantLock locker2 = new ReentrantLock(true);
        Thread t3 = new Thread(() -> {
            try {
                locker2.lock();
                count++;
            } finally {
                locker2.unlock();
            }
        });
    }
}
